#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int main()
{
    pid_t pid = 0;
    int a = 1;
    int b = 0;
    int status = 0;

    printf("Parent = %d\n", getpid());

    if ((pid = fork()) == 0)
        exit(-1);
    
    printf("Child = %d\n", pid);

    if ((pid = fork()) == 0)
        abort();

    printf("Child = %d\n", pid);

    if ((pid = fork()) == 0) {
        a = a / b; // 1/0
        exit(1);
    }

    printf("Child = %d\n", pid);

    sleep(3);

    while ((pid = wait(&status)) > 0) {
        printf("Child = %d, status = %x\n", pid, status);
    }

    return 0;
}
